<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SunCMS 后台管理系统</title>
<link href="./images/system/style.css" rel="stylesheet" type="text/css">
<script src="./include/javascript/jquery.js" type="text/javascript"></script>
<script src="./include/javascript/json.js" type="text/javascript"></script>
<script src="./include/javascript/main.js" type="text/javascript"></script>
<script type="text/javascript">
	var SCRIPT='<?php echo SCRIPT_NAME?>';
	var SITE_URL='<?php echo SITE_URL?>';
</script>
<script type="text/javascript">
var catMag = {
	_treeActive: 0,
	_saving: false,
	newCategory: function()
	{
		var pid = $("#cat_id").text();
		var model = $("#model").val();
		parent.dialog.iframe(1,'新建栏目','?m=document&a=category&do=new&model='+model+'&pid='+pid,1,1,800,450);
	},
	save: function()
	{
		if(!app.categoryCheck()||this._saving==true)return false;
		this._saving = true;
		$("#ajaxing #ajax_msg").html(" 正在保存......　");
		$("#ajaxing").show();
		var catid = $("#cat_id").text();
		var catName = $.trim($("#name").val());
		var catModel = $.trim($("#cat_model").val());
		var oldDir = $.trim($("#old_dir").val());
		var dir = $.trim($("#dir").val());
		var model = $("#model").val();
		var onepage = $("#onepage_yes").attr('checked')==true?1:0;
		var order = $.trim($("#order").val());
		var contentData = {
			'name':catName,
			'dir':dir,
			'images':$("#thumb").val(),
			'keywords':$.trim($("#keywords").val()),
			'description':$.trim($("#description").val()),
			'index_temp':$("#index_temp").val(),
			'list_temp':$("#list_temp").val(),
			'detail_temp':$("#detail_temp").val(),
			'list_rule':$.trim($("#list_rule").val()),
			'detail_rule':$.trim($("#detail_rule").val()),
			'workflow_id':$("#workflow_id").val(),
			'list_no':$.trim($("#list_no").val()),
			'order':order,
			'ifshow':$("#openshow_yes").attr('checked')==true?1:0,
			'onepage':onepage,
			'post':$("#post_yes").attr('checked')==true?1:0,
			'post_group_ids':$("#post_group_ids").val(),
			'attribute_extend':$("#attribute_extend").val(),
			'model':catModel
		};
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=document&a=category&do=update",
			data: {'data':JSON.stringify(contentData),'model':model,'catid':catid},
			error: function (xmlHttpRequest, error) {
				catMag._saving = false;
				$("#ajaxing").hide();
				parent.dialog.alert('AJAX数据获取异常！');
			},
			success: function(rs)
			{
				if(rs==1)
				{
					var oldName = $("#old_name").val();
					var oldOnepage = $("#old_onepage").val();
					var oldOrder = $("#old_order").val();
					var html = $("#cat_menu #cat_"+catid).html();
					$("#old_order").val(rs.order);
					$("#old_name").val(catName);
					$("#old_onepage").val(onepage);
					$("#old_dir").val(dir);
					if(catModel!=model||oldOrder!=order)
					{
						catMag._treeActive=catid;
						$("#model").val(catModel);
						catMag.getCategoryMenu();
					}
					else
					{
						var flag = false;
						if(oldName != catName)
						{
							html = html.replace(oldName,catName);
							flag = true;
						}
						if(onepage != oldOnepage)
						{
							html = onepage==1?html.replace(65,"68"):html.replace(68,"65");
							flag = true;
						}
						flag && $("#cat_menu #cat_"+catid).html(html);
					}
					oldDir == dir?parent.dialog.alert('栏目已保存！'):parent.dialog.alert('栏目已保存，栏目目录已被更新，请重新生成栏目首页，文档列表页和站点首页！');
				}
				else
				{
					parent.dialog.alert('栏目保存失败！');
				}
				window.setTimeout('$("#ajaxing").hide();',300);
				catMag._saving = false;
			}
		});
	},
	move: function()
	{
		var catid = $("#cat_id").text();
		var pid = $("#cat_menu #cat_"+catid).attr('pid');
		var model = $("#model").val();
		if(catid==0)parent.dialog.alert('请选择要转移的栏目！');
		else{parent.dialog.iframe(1,'请选择要转移到的栏目','?m=document&a=category&do=movecategoryset&model='+model+'&catid='+catid+'&pid='+pid+'&frame=1',1,1,500,420);}
	},
	order: function()
	{
		
	},
	moveDocConfirm: function()
	{
		
	},
	emptyDocConfirm: function()
	{
		
	},
	deleteConfirm: function()
	{
		var catid = $("#cat_id").text();
		var model = $("#model").val();
		var appdo = 'app.deleteCategory('+catid+',\''+model+'\')'
		if(catid==0){parent.dialog.query('此操作不可恢复，确定要删除所有栏目吗？',appdo);}
		else{parent.dialog.query('此操作不可恢复，是否确定？',appdo);}
	},
	getIndexTemplate: function()
	{
		
	},
	getListTemplate: function()
	{
		
	},
	getDetailTemplate: function()
	{
		
	},
	getCategoryMenu: function()
	{
		/** todo: 获取栏目树 **/
		var model = $("#model").val();
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=document&a=category&do=getcategory",
			data:{'model':model},
			error: function (xmlHttpRequest, error) {
				parent.dialog.alert('AJAX数据获取异常！');
			},
			success: function(rs)
			{
				$("#cat_menu").empty();
				var html = '';
				for(i in rs)
				{
					var treeStyle=rs[i].level>2?'none':'block';
					var active = i==0?' tree_active':'';
					html+='<div class="tree_item'+active;
					html+='" style="display:'+treeStyle+'" id="cat_'+rs[i].id+'" pid="'+rs[i].pid+'" onclick="catMag.treeClick('+rs[i].id+')" ';
					html+='>'+rs[i].img+rs[i].name+'</div>';
				}
				$("#cat_menu").html(html);
				$("#cat_menu .tree_item").removeClass("tree_active");
				var flag = catMag._treeActive==0?(rs.length>1?rs[1].id:0):catMag._treeActive;
				$("#catid").val(flag);
				catMag._treeActive==0?(flag == 0?catMag.emptyCategoryDetail():catMag.getCategoryDetail()):'';
				$("#cat_menu #cat_"+flag).addClass("tree_active");
				var status = $("#cat_menu #cat_"+flag).css('display');
				(catMag._treeActive!=0 && status=='none')?global.showCategoryParent(flag):'';
				/** todo: 将栏目保存，更新栏目树后需要添加选中状态的栏目id还原为默认设置 **/
				catMag._treeActive!=0?catMag._treeActive=0:'';
			}
		});
	},
	getCategoryDetail: function()
	{
		$("#ajaxing #ajax_msg").html(" 正在加载......　");
		$("#ajaxing").show();window.setTimeout('$("#ajaxing").hide();',300);
		var currCatId =  $("#catid").val();
		$.ajax({
			url: SITE_URL+SCRIPT+"?m=document&a=category&do=detail",
			data: {'catid':currCatId},
			error: function (xmlHttpRequest, error) {
				$("#ajaxing").hide();
				parent.dialog.alert('AJAX数据获取异常！');
			},
			success: function(rs)
			{
				$("#old_name").val(rs.name);
				$("#old_onepage").val(rs.onepage);
				$("#old_order").val(rs.order);
				$("#old_dir").val(rs.dir);
				$("#cat_id").text(rs.id);
				$("#name").val(rs.name);
				$("#cat_model").val(rs.model);
				$("#dir").val(rs.dir);
				$("#thumb_pic").val(rs.images);
				$("#keywords").val(rs.keywords);
				$("#description").val(rs.description);
				$("#index_temp").val(rs.index_temp);
				$("#list_temp").val(rs.list_temp);
				$("#detail_temp").val(rs.detail_temp);
				$("#list_rule").val(rs.list_rule);
				$("#detail_rule").val(rs.detail_rule);
				$("#workflow_id").val(rs.workflow_id);
				$("#attribute_extend").val(rs.attribute_extend);
				$("#list_no").val(rs.list_no);
				$("#order").val(rs.order);
				$("#comment_money").val(rs.comment_money);
				rs.ifshow==1?$("#openshow_yes").attr('checked','true'):$("#openshow_no").attr('checked','true');
				rs.onepage==1?$("#onepage_yes").attr('checked','true'):$("#onepage_no").attr('checked','true');
				rs.comment==1?$("#comment_yes").attr('checked','true'):$("#comment_no").attr('checked','true');
				rs.post==1?$("#post_yes").attr('checked','true'):$("#post_no").attr('checked','true');
				$("#post_group_ids").val(rs.post_group_ids);
				$("#post_money").val(rs.post_money);
				$("#money").val(rs.money);
				$("#repeat_money").val(rs.repeat_money);
				var flag=(rs.document_no>0 || rs.child==1)?true:false;
				flag?$("#onepage_yes").attr('disabled','true'):$("#onepage_yes").removeAttr('disabled');
				flag?$("#onepage_no").attr('disabled','true'):$("#onepage_no").removeAttr('disabled');
				(rs.pid!=0||flag)?$("#cat_model").attr('disabled','true'):$("#cat_model").removeAttr('disabled');
				window.setTimeout('$("#ajaxing").hide();',300);
			}
		});
	},
	emptyCategoryDetail: function()
	{
		$("#cat_id").text(0);
		$("#name").val('');
		$("#cat_model").val($("#model").val());
		$("#dir").val('');
		$("#thumb_pic").val('');
		$("#keywords").val('');
		$("#description").val('');
		$("#index_temp").val('');
		$("#list_temp").val('');
		$("#detail_temp").val('');
		$("#list_rule").val('');
		$("#detail_rule").val('');
		$("#workflow_id").val('');
		$("#list_no").val('');
		$("#order").val('');
		$("#comment_money").val('');
		$("#openshow_yes").removeAttr('checked');
		$("#openshow_no").removeAttr('checked');
		$("#onepage_yes").removeAttr('checked');
		$("#onepage_yes").removeAttr('disabled');
		$("#onepage_no").removeAttr('checked');
		$("#onepage_no").removeAttr('disabled');
		$("#comment_yes").removeAttr('checked');
		$("#comment_no").removeAttr('checked');
		$("#post_yes").removeAttr('checked');
		$("#post_no").removeAttr('checked');
		$("#post_group_ids").val('');
		$("#post_money").val('');
		$("#money").val('');
		$("#repeat_money").val('');
	},
	treeClick: function(catid)
	{
		var currCatId =  $("#catid").val();
		if(currCatId==catid)return false;
		$("#cat_menu .tree_item").removeClass("tree_active");
		$("#cat_menu #cat_"+catid).addClass("tree_active");
		$("#catid").val(catid);
		$("#cat_attribute").click();
		catid==0?this.emptyCategoryDetail():this.getCategoryDetail();
	}
}
</script>
</head>
<body>
<input type='hidden' id='catid' value='<?php echo $datas['id']; ?>'>
<input type="hidden" id='old_onepage' value='<?php echo $datas['onepage']; ?>'>
<input type="hidden" id='old_order' value='<?php echo $datas['order']; ?>'>
<input type="hidden" id='old_dir' value='<?php echo $datas['dir']; ?>'>
<table cellspacing="0" cellpadding="0" border="0" width="100%" height='100%'>
	<tr>
		<td style='width:200px;' valign='top'>
			<div class="main" style='margin-right:0px;'>
				<div class='main_left'>
					<div class='main_right' style='padding:7px;'>
						<div style='margin:0 0 5px 5px;'>
							文档模型：<select id='model' onchange='catMag.getCategoryMenu();' style='height:18px; width:75px;'>
								<option value='article'>&nbsp;&nbsp;文章
								<option value='picture'>&nbsp;&nbsp;图片
								<option value='video'>&nbsp;&nbsp;视频
								<option value='download'>&nbsp;&nbsp;下载
								<option value='product'>&nbsp;&nbsp;产品
							</select>
						</div>
						<div id='cat_menu'>
							<?php foreach( $tree as $v ){?>
							<div class="tree_item <?php if($datas['id']==$v['id'])echo 'tree_active'; ?>" id="cat_<?php echo $v['id']; ?>" pid="<?php echo $v['pid'].'" '; if($v['level']>2){ ?> style='display:none;' <?php } ?>onclick="catMag.treeClick(<?php echo $v['id']; ?>);"<?php echo '>'.$v['img'].$v['name']; ?></div>
							<?php }?>
						</div>
					</div><!-- /main_right -->
				</div><!-- /main_left -->
			</div><!-- /main -->
		</td>
		<td valign='top' id="category_detial">
			<div class="main">
				<div class='main_left'>
					<div class='main_right'>
						<table cellspacing="0" cellpadding="0" border="0" width="100%">
							<tr>
								<td>
									<div class='nav_info'>
										<div class='info category_attribute' onclick='global.tab(1);' id='cat_attribute'><img src="./images/system/icon/34.gif"/><b>栏目属性</b></div>
										<div class='info2 category_attribute' onclick='global.tab(2);'><img src="./images/system/icon/34.gif"/><b>扩展属性</b></div>
									</div>
									<div class='f_left' id='tb_menu1'>
										<a class='sbutton' onclick="catMag.save();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/40.gif"/><b>保存</b></a>
										<a class='sbutton' onclick="catMag.newCategory();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/36.gif"/><b>新建</b></a>
										<a class='sbutton' onclick="catMag.move();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/43.gif"/><b>移动</b></a>
										<a class='sbutton' onclick="catMag.deleteConfirm();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/44.gif"/><b>删除</b></a>
										<a class='sbutton' onclick="catMag.order();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/43.gif"/><b>排序</b></a>
										<a class='sbutton' onclick="catMag.moveDocConfirm();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/41.gif"/><b>转移文档</b></a>
										<a class='sbutton' onclick="catMag.emptyDocConfirm();" href="javascript:void(0);"><img height="20" width="20" src="./images/system/icon/42.gif"/><b>清空文档</b></a>
									</div>
								</td>
							</tr>
							<tr>
								<td style="padding-top: 5px;*padding-top:0;">
								<div  id="stab_1">
									<table cellspacing="0" cellpadding="2" width="100%" class="itable">
									<tr style='height:23px;'>
										<td width="13%" align='right'>ID：</td>
										<td id='cat_id' ><?php echo $datas['id']; ?></td>
									</tr>
									<tr>
										<td align='right'>所属模型：</td>
										<td>
											<select id='cat_model' class='sinput tp2' <?php if($datas['pid']!=0||$datas['document_no']>0||$datas['child']==1)echo 'disabled'; ?>>
												<option value='article' <?php if($datas['model']=='article')echo 'selected'; ?>>&nbsp;文章
												<option value='picture' <?php if($datas['model']=='picture')echo 'selected'; ?>>&nbsp;图片
												<option value='video' <?php if($datas['model']=='video')echo 'selected'; ?>>&nbsp;视频
												<option value='download' <?php if($datas['model']=='download')echo 'selected'; ?>>&nbsp;下载
												<option value='product' <?php if($datas['model']=='product')echo 'selected'; ?>>&nbsp;产品
											</select>
										</td>
									</tr>
									<tr>
										<td align='right'>栏目名称：</td>
										<td>
											<input type="text" class="sinput tp2" id='name' value='<?php echo $datas['name']; ?>' />
											<span style="color: red; padding-left: 2px; ">*</span>
											<input type="hidden" id='old_name' value='<?php echo $datas['name']; ?>' />
										</td>
									</tr>
									<tr>
										<td align='right'>栏目目录：</td>
										<td>
											<input type="text" class="sinput tp2" id='dir' value='<?php echo $datas['dir']; ?>' />
											<span style="color: red; padding-left: 2px;">*</span>
										</td>
									</tr>
									<tr>
										<td align='right'>栏目引导图：</td>
										<td>
											<input type="text" id="thumb_pic" class="sinput tp2" readonly value='<?php echo $datas['images']; ?>'/>
											<a class="slbutton" href="javascript:void(0);" onclick="global.thumbUpload();"><input type="button" class="srbutton" value="上传"/></a>
										</td>
									</tr>
									<tr>
										<td align='right'>栏目关键词：</td>
										<td><input type="text" id='keywords' class="sinput tp2" value='<?php echo $datas['keywords']; ?>'/></td>
									</tr>
									<tr>
										<td align='right' valign='top'>栏目描述：</td>
										<td><textarea cols='75' id='description'><?php echo $datas['description']; ?></textarea></td>
									</tr>
									<tr>
										<td align='right'>首页模板：</td>
										<td>
											<input type="text" id='index_temp' class="sinput tp2" value='<?php echo $datas['index_temp']; ?>' readonly />
											<a class="slbutton" href="javascript:void(0);" onclick="catMag.getIndexTemplate();"><input type="button" class="srbutton" value="选择.."/></a>
										</td>
									</tr>
									<tr>
										<td align='right'>列表页模板：</td>
										<td>
											<input type="text" id='list_temp' class="sinput tp2" value='<?php echo $datas['list_temp']; ?>' readonly />
											<a class="slbutton" href="javascript:void(0);" onclick="catMag.getListTemplate();"><input type="button" class="srbutton" value="选择.."/></a>
										</td>
									</tr>
									<tr>
										<td align='right'>详细页模板：</td>
										<td>
											<input type="text" id='detail_temp' class="sinput tp2" value='<?php echo $datas['detail_temp']; ?>' readonly />
											<a class="slbutton" href="javascript:void(0);" onclick="catMag.getDetailTemplate();"><input type="button" class="srbutton" value="选择.."/></a>
										</td>
									</tr>
									<tr>
										<td  align="right">列表页命名规则：</td>
										<td>
											<input type="text" class='sinput tp2' id="list_rule" value="<?php $datas['list_rule']; ?>" size="30"/>
										</td>
									</tr>
									<tr>
										<td align='right'>详细页命名规则：</td>
										<td><input type="text" id='detail_rule' class="sinput tp2" value='<?php echo $datas['detail_rule']; ?>' /></td>
									</tr>
									<tr>
										<td align="right">排序权值：</td>
										<td align="left">
											<input type="text" id='order'  class='sinput tp2' value='<?php echo $datas['order']; ?>' />
										</td>
									</tr>
									<tr style='height:23px;'>
										<td align='right'>是否单页面：</td>
										<td>
											<input type="radio" name="onepage" value='1' id='onepage_yes' <?php if($datas['document_no']>1||$datas['child'])echo 'disabled';if($datas['onepage']==1)echo ' checked'; ?>>是
											<input type="radio" name="onepage" value='0' id='onepage_no' <?php if($datas['document_no']>1||$datas['child'])echo 'disabled';if($datas['onepage']==0)echo ' checked'; ?>>否
										</td>
									</tr>
									</table>
								</div>
							<div id="stab_2" style='display:none;'>
								<table cellspacing="0" cellpadding="2" width="100%" class="itable">
									<tr style='height:23px;'>
										<td width="13%" align='right'>是否开放显示：</td>
										<td>
											<input type="radio" name="show" id='openshow_yes' value='1' <?php if($datas['ifshow']==1)echo 'checked'; ?>>是
											<input type="radio" name="show" id='openshow_no' value='0' <?php if($datas['ifshow']==0)echo 'checked'; ?>>否
										</td>
									</tr>
									<tr style='height:23px;'>
										<td align='right'>是否允许投稿：</td>
										<td>
											<input type="radio" name="ifpost" id='post_yes' value='1' <?php if($datas['post']==1)echo 'checked'; ?>>是
											<input type="radio" name="ifpost" id='post_no'  value='0' <?php if($datas['post']==0)echo 'checked'; ?>>否
										</td>
									</tr>
									<tr>
										<td align='right'>允许投稿会员组：</td>
										<td>
											<input type="text" id='post_group_ids' class="sinput tp2" readonly value='<?php echo $datas['post_group_ids']; ?>' />
											<a class="slbutton" href="javascript:void(0);" onclick="catMag.getPostGroup();"><input type="button" class="srbutton" value="选择.."/></a>
										</td>
									</tr>
									<tr>
										<td align='right'>工作流：</td>
										<td>
											<input type="text" id='workflow_id' class="sinput tp2" value='<?php echo $datas['workflow_id']; ?>' readonly />
											<a class="slbutton" href="javascript:void(0);" onclick="catMag.getWorkflow();"><input type="button" class="srbutton" value="选择.."/></a>
										</td>
									</tr>
									<tr>
										<td align='right'>列表页项目数：</td>
										<td><input type="text" id='list_no' class="sinput tp2" value='<?php echo $datas['list_no']; ?>' /></td>
									</tr>
									<tr>
										<td align='right'>属性沿用：</td>
										<td>
											<select id='attribute_extend' class='sinput tp2'>
												<option value='0'>仅本栏目
												<option value='1'>所有子栏目
											</select>
										</td>
									</tr>
								</table>
							</div>
							</td>
							</tr>
						</table>
					</div><!-- /main_right -->
				</div><!-- /main_left -->
			</div><!-- /main -->
		</td>
	</tr>
</table>
<div id="ajaxing" style="padding-top: 5px; background-color: #FFFFCC; position: absolute; z-index: 801; height: 20px; width: 120px; top: 84px;*top:91px; left: 218px;display:none;">
	<img src="./images/system/icon/67.gif"/><font style='color:#008000;' id='ajax_msg'> 正在加载......　</font>
</div>
</body>
</html>